signature QUAD =
sig
(* to transform tree statemnets and expressions into qudrables*)
val quadgenstms : Tree.stm list ->Tree.stm list
val quadgenstm : Tree.stm  ->Tree.stm 
end

structure Quad:QUAD =
struct

structure R = Tree
structure M = Temp

fun quadgenstm ( R.LABEL label) = R.LABEL label
| quadgenstm (R.JUMP (e, llist)) = R.JUMP (quadgenexp e , llist)
| quadgenstm (R.CJUMP (rop,e1,e2,l1,l2)) = R.CJUMP(rop,quadgenexp e1,quadgenexp e2,l1,l2)
| quadgenstm (R.MOVE(e1,e2)) = R.MOVE(quadgenexp e1 , quadgenexp e2)
| quadgenstm (R.SEQ (s1,s2)) = R.SEQ (quadgenstm s1, quadgenstm s2)
| quadgenstm (R.EXP e) = R.EXP (quadgenexp e)

and quadgenexp (R.TEMP t) = R.TEMP t
| quadgenexp (R.NAME label) = R.NAME label
| quadgenexp (R.CONST i) = R.CONST i
| quadgenexp (R.MEM e) =
let val t = R.TEMP (M.newtemp())
in R.ESEQ (R.MOVE (t, quadgenexp e) ,R.MEM t)
end
| quadgenexp (R.ESEQ (s,e)) = R.ESEQ (quadgenstm s, quadgenexp e)
| quadgenexp (R.CALL (n,[])) = R.CALL (n,[])
| quadgenexp (R.CALL (n,elist)) = R.CALL (n, map quadgenexp elist)
| quadgenexp (R.BINOP (opr,e1,e2)) =
let val t = R.TEMP (M.newtemp())
in
R.ESEQ (R.MOVE(t, R.BINOP (opr, quadgenexp e1 , quadgenexp e2 )), t)
end

fun quadgenstms stms= map quadgenstm stms

end

 
